open(BUFF,"chr22_out_ori.tped") or die "no file exists\n";
$i=0;
while(<BUFF>)
{
	chomp($_);
	@a=split(" ",$_);
	$hash{$a[1]}=$i++;
}
open(BUFF,"gunzip -c beagle.dosage.gz|") or die " no file exists\n";
open(WRBUFF,"|gzip >beagle_final.gz");
#$line=<BUFF>;
while(<BUFF>)
{
	#print "$.\n";
        chomp($_);
        @a=split(" ",$_);
	if(exists($hash{$a[0]}))
	{
		$am[$hash{$a[0]}]=$_;
	}
}
for($i=0;$i<@am;$i++)
{
	if($am[$i] !~ m/\w/)
	{
		die "$i $am[$i]\n";
	}	
	print WRBUFF $am[$i]."\n";
}
